﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using SmartPlant.Model.Biz;
using SmartPlant.Modules.Base.UIEntity;
using SmartPlant.Modules.Base.ViewModels;

namespace SmartPlant.Modules.Base.Selector
{
    /// <summary>
    /// 选择器。用于在CommonProperty.xaml
    /// </summary>
    public class TabControlDataTemplateSelector : DataTemplateSelector
    {
        public DataTemplate TextTemplate { get; set; }
        public DataTemplate ComboxTemplate { get; set; }
        public DataTemplate TextComboxTemplate { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            ContentItemModel contextItemModel = item as ContentItemModel;
            if (contextItemModel != null)
            {
                switch (contextItemModel.Type)
                {
                    case ContentItemType.Text: //纯文本
                        return TextTemplate;
                    case ContentItemType.Combox: //下拉列表
                        return ComboxTemplate;
                    case ContentItemType.TextCombox:
                        return TextComboxTemplate;
                    default:
                        return TextTemplate;
                }
            }
            return base.SelectTemplate(item, container);
        }
    }

    public class NameDataTemplateSelector : DataTemplateSelector
    {
        public DataTemplate TextTemplate { get; set; }
        public DataTemplate TextBlockTemplate { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            UnitTagConvention unitTagConvention = item as UnitTagConvention;
            if (unitTagConvention != null)
            {
                return unitTagConvention.IsReadOnly switch
                {
                    //纯文本
                    true => TextBlockTemplate,
                    //下拉列表
                    false => TextTemplate,
                };
            }
            return base.SelectTemplate(item, container);
        }
    }
}
